<script setup lang="ts">
import {ref} from "vue";
import myAxios from "../plugins/MyAxios.ts";
import {useRouter} from "vue-router";


const router = useRouter()
const userAccount = ref('');
const userPassword = ref('');
const isLoading = ref(false);

const onSubmit = async () => {
  isLoading.value = true;
  try {
    const resp = await myAxios.post("/user/login", {
      userAccount: userAccount.value,
      userPassword: userPassword.value,
    });
    if (resp.status === 0 && resp.data) {
      router.replace('/');
    }
  } catch (error) {
    console.error('登录失败:', error);
  } finally {
    isLoading.value = false;
  }
};

</script>

<template>
  <div class="login-page">
    <!-- 登录表单容器 -->
    <div class="login-container">
      <!-- 标题区域 -->
      <div class="login-header">
        <h1 class="login-title">找朋友</h1>
        <p class="login-subtitle">发现志同道合的朋友</p>
      </div>
      
      <!-- 登录表单 -->
      <van-form @submit="onSubmit" class="login-form">
        <van-cell-group inset class="form-group">
          <van-field
              v-model="userAccount"
              name="userAccount"
              label="账号"
              placeholder="请输入账号"
              :rules="[{ required: true, message: '请填写账号' }]"
              class="form-field"
              left-icon="user-o"
          />
          <van-field
              v-model="userPassword"
              type="password"
              name="userPassword"
              label="密码"
              placeholder="请输入密码"
              :rules="[{ required: true, message: '请填写密码' }]"
              class="form-field"
              left-icon="lock"
          />
        </van-cell-group>
        
        <div class="login-button-container">
          <van-button 
            round 
            block 
            type="primary" 
            native-type="submit"
            class="login-button"
            :loading="isLoading"
          >
            <van-icon name="sign" size="16" />
            登录
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<style scoped>
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: transparent;
}

.login-container {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 24px;
  padding: 40px 32px;
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: fadeInUp 0.8s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-title {
  font-size: 32px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 8px 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  font-size: 16px;
  color: #7f8c8d;
  margin: 0;
  font-weight: 400;
}

.login-form {
  width: 100%;
}

.form-group {
  background: transparent;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 24px;
}

.form-field {
  background: rgba(248, 249, 250, 0.8);
  border-radius: 12px;
  margin-bottom: 16px;
  transition: all 0.3s ease;
}

.form-field:last-child {
  margin-bottom: 0;
}

.login-button-container {
  margin-top: 24px;
}

.login-button {
  height: 52px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 26px;
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(102, 126, 234, 0.4);
}

.login-button:active {
  transform: translateY(0);
}

/* 深度选择器优化 Vant 组件样式 */
:deep(.van-field__control) {
  color: #2c3e50;
  font-size: 16px;
}

:deep(.van-field__control::placeholder) {
  color: #bdc3c7;
}

:deep(.van-field__label) {
  color: #5a6c7d;
  font-weight: 500;
}

:deep(.van-field__left-icon) {
  color: #667eea;
}

:deep(.van-cell-group--inset) {
  background: transparent;
  box-shadow: none;
  border-radius: 16px;
}

:deep(.van-cell) {
  background: rgba(248, 249, 250, 0.8);
  border-radius: 12px;
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid rgba(102, 126, 234, 0.1);
  transition: all 0.3s ease;
}

:deep(.van-cell:focus-within) {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
  background: rgba(255, 255, 255, 0.9);
}

:deep(.van-cell:last-child) {
  margin-bottom: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .login-page {
    padding: 16px;
  }
  
  .login-container {
    padding: 32px 24px;
  }
  
  .login-title {
    font-size: 28px;
  }
  
  .login-subtitle {
    font-size: 14px;
  }
  
  .login-button {
    height: 48px;
    font-size: 15px;
  }
}
</style>